/*
 * Copyright (C) 2014 STNet,Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package jp.co.stnet.apps.medcloud.web.api.resources;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import jp.co.stnet.apps.medcloud.domain.beans.UserProfile;
import jp.co.stnet.apps.medcloud.domain.services.api.PharmacyListResourceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * 会員用の REST サービスです.
 *
 * @author stnetadmin
 */
@Path("/member/getInfo")
@Service
public class MemberResource {

    private static final Logger logger = LoggerFactory.getLogger(MemberResource.class);

    @Autowired
    private PharmacyListResourceService pharmacyLogic;

    /**
     * テスト
     *
     * @return
     */
    @GET
    public String getMyInfo() {
        // SecurityContextHolder経由でどこからでもユーザ認証情報は取得可能
        Authentication auth
                = SecurityContextHolder.getContext().getAuthentication();
        UserProfile profile
                = (jp.co.stnet.apps.medcloud.domain.beans.UserProfile) auth.getPrincipal();
        logger.debug("\n\tSecurityContextHolder username: " + profile.getUsername());

        return "\n\tProtected Resource(getInfo) Accessed !! Returning from resource getInfo";
    }

}
